package com.app.micaihu.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.news.VideoRankEntity;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.image.LoadImageUtils;
import com.baidu.mobstat.StatService;

import java.util.List;

/**
 * Created by Guo on 2017/5/22.
 *
 * 视频 排行榜的adapter
 *
 *
 *
 */

public class VideoRankAdapter extends AppBaseAdapter<VideoRankEntity> {
    public VideoRankAdapter(List<VideoRankEntity> list, Context context) {
        super(list, context);
    }

    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
       ViewHolder viewHolder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.item_video_rank,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        StatService.onEvent(context, "article_exposed", "视频榜_视频", 1);// 统计的点击的次数
        VideoRankEntity videoRankEntity = list.get(position);
        if(videoRankEntity == null){
            return convertView;
        }

        viewHolder.tvTitle.setText(videoRankEntity.getArticleTitle());
        viewHolder.tvDesc.setText(videoRankEntity.getPeriod());
        if(videoRankEntity.getArticleThumb() != null && videoRankEntity.getArticleThumb().length > 0){
            LoadImageUtils.getInstance().loadImage(viewHolder.icvThumb,videoRankEntity.getArticleThumb()[0]);

        }
        viewHolder.tvCount.setText(videoRankEntity.getClickNum()+"播放");

        viewHolder.numTv.setVisibility(View.INVISIBLE);
        viewHolder.numIcon.setVisibility(View.VISIBLE);
        if(position == 0){
            viewHolder.numIcon.setImageResource(R.drawable.game_ranking_a);
        }else if(position == 1){
            viewHolder.numIcon.setImageResource(R.drawable.game_ranking_b);
        }else if(position == 2){
            viewHolder.numIcon.setImageResource(R.drawable.game_ranking_c);
        }else{
            viewHolder.numTv.setVisibility(View.VISIBLE);
            viewHolder.numIcon.setVisibility(View.INVISIBLE);
            viewHolder.numTv.setText((position+1)+ "");
        }
        return convertView;
    }




    class ViewHolder{
        private TextView tvTitle;
        private TextView tvDesc;
        private TextView tvCount;
        private CustomImageView icvThumb;

        private ImageView numIcon;
        private TextView numTv;
        public ViewHolder(View contentView){
            tvTitle = (TextView)contentView.findViewById(R.id.video_title);
            tvDesc = (TextView)contentView.findViewById(R.id.video_time);
            tvCount = (TextView)contentView.findViewById(R.id.video_count);
            numTv = (TextView)contentView.findViewById(R.id.tv_rank_num);
            numIcon = (ImageView) contentView.findViewById(R.id.iv_rank_num);
            icvThumb = (CustomImageView) contentView.findViewById(R.id.video_logo);

        }

    }
}
